package com.centling.smartSealForPhone.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.bean.ChangeSeal;
import com.centling.smartSealForPhone.constants.UrlConstants;
import com.centling.smartSealForPhone.utils.ImageUtil;
import com.centling.smartSealForPhone.view.RoundImgView;
import com.google.gson.Gson;

public class SealChangeDetailActivity extends TitleBarActivity {
    private TextView tvStatus;
    private RoundImgView ivAvatar;
    private TextView tvApply;
    private TextView tvOperate;
    private TextView tvDate;
    private TextView tvReason;
    private LinearLayout llFail;
    private TextView tvFailReason;
    private TextView tvIsValid;
    private ChangeSeal item;

    private TextView newSeal;
    private TextView oldSeal;

    private TextView detailBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seal_change_detail);
        setTitleBarText("换章详情");
        String json = getIntent().getStringExtra("changeSeal");
        item = new Gson().fromJson(json, ChangeSeal.class);


        initView();
        setData();
    }

    public void initView() {
        detailBtn = (TextView) findViewById(R.id.tv_stamp_detail_btn);
        tvStatus = (TextView) findViewById(R.id.seal_change_detail_status);
        ivAvatar = (RoundImgView) findViewById(R.id.seal_change_detail_avatar);
        tvApply = (TextView) findViewById(R.id.seal_change_detail_apply);
        tvOperate = (TextView) findViewById(R.id.seal_change_detail_operate);
        tvDate = (TextView) findViewById(R.id.seal_change_detail_date);
        tvReason = (TextView) findViewById(R.id.seal_change_detail_reason);
        llFail = (LinearLayout) findViewById(R.id.seal_change_detail_fail);
        tvFailReason = (TextView) findViewById(R.id.seal_change_detail_fail_reason);
        tvIsValid = (TextView) findViewById(R.id.seal_change_detail_isValid);

        newSeal = (TextView) findViewById(R.id.seal_change_detail_new);
        oldSeal = (TextView) findViewById(R.id.seal_change_detail_old);
    }

    public void setData() {
        switch (item.getStatus()) {
            case "-1":
                tvStatus.setText("审核过期");
                break;
            case "-2":
                tvStatus.setText("授权过期");
                break;
            case "0":
                tvStatus.setText("审核中");
                break;
            case "1":
                tvStatus.setText("审核通过");
                break;
            case "2":
                tvStatus.setText("审核失败");
                llFail.setVisibility(View.VISIBLE);
                tvFailReason.setText(item.getCheckedFailReason());
                break;
            case "3":
                tvStatus.setText("换章结束");
                break;
            case "4":
                tvStatus.setText("放弃执行");
                break;
            case "5":
                tvStatus.setText("换章中");
                break;
            default:
                tvStatus.setText("失效");
                break;
        }

        if ("0".equals(item.getIsValid())) {
            tvIsValid.setText("正常");
        } else {
            tvIsValid.setText("换章失效");
        }
        if ("0".equals(item.getIsValid()) && "1".equals(item.getStatus())) {
            detailBtn.setVisibility(View.VISIBLE);
            detailBtn.setText("点击进行换章操作");
            detailBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(SealChangeDetailActivity.this,SealChangeTipsActivity.class);
                    intent.putExtra("applyId", item.getReplaceSealApplyId());
                    startActivity(intent);
                    finish();
                }
            });
        }

        newSeal.setText(item.getSealNameNew());
        oldSeal.setText(item.getOldSealName());
        ImageUtil.loadAvatarImage(item.getApplicantUserAvatar(),ivAvatar,R.drawable.iv_avatar_default);
        tvApply.setText(item.getApplicantUserName());
        tvOperate.setText(item.getExecutorUserName());
        tvDate.setText(item.getCreatedDateStr());
        tvReason.setText(item.getReason());
    }
}
